﻿// MedicalRulesEngine.Core/DTOs/RuleDto.cs
namespace MedicalRulesEngine.Core.DTOs;

/// <summary>
/// 规则数据传输对象
/// 用于API接口的数据传输
/// </summary>
public class RuleDto
{
    /// <summary>
    /// 规则ID
    /// </summary>
    public string Id { get; set; } = string.Empty;

    /// <summary>
    /// 规则名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 规则编码
    /// </summary>
    public string Code { get; set; } = string.Empty;

    /// <summary>
    /// 规则描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 工作流名称
    /// </summary>
    public string WorkflowName { get; set; } = string.Empty;

    /// <summary>
    /// 分类
    /// </summary>
    public string Category { get; set; } = string.Empty;

    /// <summary>
    /// 子分类
    /// </summary>
    public string? SubCategory { get; set; }

    /// <summary>
    /// 优先级
    /// </summary>
    public int Priority { get; set; }

    /// <summary>
    /// 是否启用
    /// </summary>
    public bool IsEnabled { get; set; }

    /// <summary>
    /// 规则表达式
    /// </summary>
    public string? Expression { get; set; }

    /// <summary>
    /// 状态
    /// </summary>
    public int Status { get; set; }

    /// <summary>
    /// 版本号
    /// </summary>
    public int Version { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedAt { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdatedAt { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    public string? CreatedBy { get; set; }

    /// <summary>
    /// 更新人
    /// </summary>
    public string? UpdatedBy { get; set; }

    /// <summary>
    /// 元数据
    /// </summary>
    public object? Metadata { get; set; }

    /// <summary>
    /// 条件集合
    /// </summary>
    public List<RuleConditionDto> Conditions { get; set; } = new();

    /// <summary>
    /// 动作集合
    /// </summary>
    public List<RuleActionDto> Actions { get; set; } = new();

    /// <summary>
    /// 标签集合
    /// </summary>
    public List<RuleTagDto> Tags { get; set; } = new();
}

/// <summary>
/// 规则条件数据传输对象
/// </summary>
public class RuleConditionDto
{
    /// <summary>
    /// 条件ID
    /// </summary>
    public string Id { get; set; } = string.Empty;

    /// <summary>
    /// 字段路径
    /// </summary>
    public string FieldPath { get; set; } = string.Empty;

    /// <summary>
    /// 操作符
    /// </summary>
    public string Operator { get; set; } = string.Empty;

    /// <summary>
    /// 比较值
    /// </summary>
    public object? Value { get; set; }

    /// <summary>
    /// 逻辑操作符
    /// </summary>
    public string LogicalOperator { get; set; } = "AND";

    /// <summary>
    /// 排序
    /// </summary>
    public int Order { get; set; }

    /// <summary>
    /// 父条件ID
    /// </summary>
    public string? ParentConditionId { get; set; }

    /// <summary>
    /// 分组名称
    /// </summary>
    public string? GroupName { get; set; }

    /// <summary>
    /// 元数据
    /// </summary>
    public object? Metadata { get; set; }

    /// <summary>
    /// 子条件集合
    /// </summary>
    public List<RuleConditionDto> ChildConditions { get; set; } = new();
}

/// <summary>
/// 规则动作数据传输对象
/// </summary>
public class RuleActionDto
{
    /// <summary>
    /// 动作ID
    /// </summary>
    public string Id { get; set; } = string.Empty;

    /// <summary>
    /// 动作名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 动作类型
    /// </summary>
    public string ActionType { get; set; } = string.Empty;

    /// <summary>
    /// 动作配置
    /// </summary>
    public object? Config { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int Order { get; set; }

    /// <summary>
    /// 是否启用
    /// </summary>
    public bool IsEnabled { get; set; }
}

/// <summary>
/// 规则标签数据传输对象
/// </summary>
public class RuleTagDto
{
    /// <summary>
    /// 标签ID
    /// </summary>
    public string Id { get; set; } = string.Empty;

    /// <summary>
    /// 标签名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 标签值
    /// </summary>
    public string? Value { get; set; }

    /// <summary>
    /// 标签颜色
    /// </summary>
    public string? Color { get; set; }
}

/// <summary>
/// 创建规则请求对象
/// </summary>
public class CreateRuleRequest
{
    /// <summary>
    /// 规则名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 规则编码
    /// </summary>
    public string Code { get; set; } = string.Empty;

    /// <summary>
    /// 规则描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 工作流名称
    /// </summary>
    public string WorkflowName { get; set; } = string.Empty;

    /// <summary>
    /// 分类
    /// </summary>
    public string Category { get; set; } = string.Empty;

    /// <summary>
    /// 子分类
    /// </summary>
    public string? SubCategory { get; set; }

    /// <summary>
    /// 优先级
    /// </summary>
    public int Priority { get; set; } = 2;

    /// <summary>
    /// 元数据
    /// </summary>
    public object? Metadata { get; set; }

    /// <summary>
    /// 条件集合
    /// </summary>
    public List<CreateRuleConditionRequest> Conditions { get; set; } = new();

    /// <summary>
    /// 动作集合
    /// </summary>
    public List<CreateRuleActionRequest> Actions { get; set; } = new();

    /// <summary>
    /// 标签集合
    /// </summary>
    public List<CreateRuleTagRequest> Tags { get; set; } = new();
}

/// <summary>
/// 创建规则条件请求对象
/// </summary>
public class CreateRuleConditionRequest
{
    /// <summary>
    /// 字段路径
    /// </summary>
    public string FieldPath { get; set; } = string.Empty;

    /// <summary>
    /// 操作符
    /// </summary>
    public string Operator { get; set; } = string.Empty;

    /// <summary>
    /// 比较值
    /// </summary>
    public object? Value { get; set; }

    /// <summary>
    /// 逻辑操作符
    /// </summary>
    public string LogicalOperator { get; set; } = "AND";

    /// <summary>
    /// 排序
    /// </summary>
    public int Order { get; set; }

    /// <summary>
    /// 父条件ID
    /// </summary>
    public string? ParentConditionId { get; set; }

    /// <summary>
    /// 分组名称
    /// </summary>
    public string? GroupName { get; set; }

    /// <summary>
    /// 元数据
    /// </summary>
    public object? Metadata { get; set; }
}

/// <summary>
/// 创建规则动作请求对象
/// </summary>
public class CreateRuleActionRequest
{
    /// <summary>
    /// 动作名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 动作类型
    /// </summary>
    public string ActionType { get; set; } = string.Empty;

    /// <summary>
    /// 动作配置
    /// </summary>
    public object? Config { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int Order { get; set; }

    /// <summary>
    /// 是否启用
    /// </summary>
    public bool IsEnabled { get; set; } = true;
}

/// <summary>
/// 创建规则标签请求对象
/// </summary>
public class CreateRuleTagRequest
{
    /// <summary>
    /// 标签名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 标签值
    /// </summary>
    public string? Value { get; set; }

    /// <summary>
    /// 标签颜色
    /// </summary>
    public string? Color { get; set; }
}

/// <summary>
/// 更新规则请求对象
/// </summary>
public class UpdateRuleRequest
{
    /// <summary>
    /// 规则名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 规则描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 分类
    /// </summary>
    public string Category { get; set; } = string.Empty;

    /// <summary>
    /// 子分类
    /// </summary>
    public string? SubCategory { get; set; }

    /// <summary>
    /// 优先级
    /// </summary>
    public int Priority { get; set; }

    /// <summary>
    /// 是否启用
    /// </summary>
    public bool IsEnabled { get; set; }

    /// <summary>
    /// 元数据
    /// </summary>
    public object? Metadata { get; set; }

    /// <summary>
    /// 条件集合
    /// </summary>
    public List<CreateRuleConditionRequest> Conditions { get; set; } = new();

    /// <summary>
    /// 动作集合
    /// </summary>
    public List<CreateRuleActionRequest> Actions { get; set; } = new();

    /// <summary>
    /// 标签集合
    /// </summary>
    public List<CreateRuleTagRequest> Tags { get; set; } = new();
}

/// <summary>
/// 字段定义数据传输对象
/// </summary>
public class FieldDefinitionDto
{
    /// <summary>
    /// 字段ID
    /// </summary>
    public string Id { get; set; } = string.Empty;

    /// <summary>
    /// 字段名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// 字段路径
    /// </summary>
    public string Path { get; set; } = string.Empty;

    /// <summary>
    /// 显示名称
    /// </summary>
    public string DisplayName { get; set; } = string.Empty;

    /// <summary>
    /// 字段描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 数据类型
    /// </summary>
    public string DataType { get; set; } = string.Empty;

    /// <summary>
    /// 分类
    /// </summary>
    public string Category { get; set; } = string.Empty;

    /// <summary>
    /// 是否必填
    /// </summary>
    public bool IsRequired { get; set; }

    /// <summary>
    /// 是否可用于条件
    /// </summary>
    public bool IsConditionable { get; set; }

    /// <summary>
    /// 支持的操作符
    /// </summary>
    public List<string> SupportedOperators { get; set; } = new();

    /// <summary>
    /// 字段配置
    /// </summary>
    public object? Config { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int Order { get; set; }
}

/// <summary>
/// 操作符定义数据传输对象
/// </summary>
public class OperatorDefinitionDto
{
    /// <summary>
    /// 操作符ID
    /// </summary>
    public string Id { get; set; } = string.Empty;

    /// <summary>
    /// 操作符代码
    /// </summary>
    public string Code { get; set; } = string.Empty;

    /// <summary>
    /// 显示名称
    /// </summary>
    public string DisplayName { get; set; } = string.Empty;

    /// <summary>
    /// 描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 支持的数据类型
    /// </summary>
    public List<string> SupportedDataTypes { get; set; } = new();

    /// <summary>
    /// 分类
    /// </summary>
    public string? Category { get; set; }

    /// <summary>
    /// 是否需要值输入
    /// </summary>
    public bool RequiresValue { get; set; }

    /// <summary>
    /// 是否支持多值
    /// </summary>
    public bool SupportsMultipleValues { get; set; }

    /// <summary>
    /// 表达式模板
    /// </summary>
    public string? ExpressionTemplate { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    public int Order { get; set; }
}
